#include "city_add_dialog.h"
#include "ui_city_add_dialog.h"

city_add_Dialog::city_add_Dialog(QSet<QString>& City_name, QSet<QString>& Country_name, QWidget *parent) :
    QDialog(parent),
    ui(new Ui::city_add_Dialog),
    city_name(City_name),
    country_name(Country_name)

{
     ui->setupUi(this);
     for(auto e : city_name)
     {
         ui->comboBox_city->addItem(e);
     }
     for(auto e : country_name)
     {
         ui->comboBox_country->addItem(e);
     }
}

city_add_Dialog::~city_add_Dialog()
{
    delete ui;
}

City city_add_Dialog::getcit()
{
    return this->cit;
}

void city_add_Dialog::on_pushButton_canle_clicked()
{
    this->close();
}

void city_add_Dialog::on_pushButton_ok_clicked()
{
    QString country = ui->comboBox_country->currentText();
    QString name = ui->comboBox_city->currentText();
    QDate day = ui->dateEdit->date();
    int New = ui->spinBox_new->value();
    int now = ui->spinBox_now->value();
    int cure = ui->spinBox_cure->value();
    int dead = ui->spinBox_dead->value();
    int all = ui->spinBox_all->value();

    QMessageBox mess;
    if(country == "" || name == "" || New < 0 || now < 0 || cure < 0 || dead < 0 || all < 0)
    {
        mess.setText("输入数据有误，请检查!");
        mess.exec();
        return;
    }

    this->cit = City(name,country,New,now,all,cure,dead,day);
    this->accept();
    this->close();
}
